package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.InOutRecordBean;
import com.wenlin.myproduction.util.UI;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @desc: 借还记录
 * @author: 文琳
 * @time: 2025/11/13 周四 9:32
 */
public class InOutRecordBinder extends ItemViewBinder<InOutRecordBean, InOutRecordBinder.VH> {
    private OnClickListener listener;

    public InOutRecordBinder(OnClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected VH onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new VH(inflater.inflate(R.layout.item_in_out_record, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull VH holder, @NonNull InOutRecordBean item) {
        UI.setText(holder.tvPosition, item.getPosition());
        UI.setText(holder.tvDate, item.getDate());
        UI.setText(holder.tvName, item.getDesc());
        UI.setText(holder.tvPrice, item.getMoney());
        UI.setOnClickListener(holder.itemView, v -> {
            if (listener != null) listener.onClick(item);
        });
    }

    static class VH extends RecyclerView.ViewHolder {
        TextView tvPosition, tvDate, tvName, tvPrice;

        public VH(@NonNull View itemView) {
            super(itemView);
            tvPosition = itemView.findViewById(R.id.tv_position);
            tvDate = itemView.findViewById(R.id.tv_date);
            tvName = itemView.findViewById(R.id.tv_name);
            tvPrice = itemView.findViewById(R.id.tv_price);
        }
    }

    public interface OnClickListener {
        void onClick(InOutRecordBean bean);
    }
}
